//
//  AggregateViewController.swift
//  SwiftTest
//
//  Created by midea on 16/3/9.
//  Copyright © 2016年 Vincent. All rights reserved.
//

import Foundation
import UIKit

class ArrayViewController : BaseViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.titles = ["statement","append","indexes","remove","ergodic"]
        self.tableView?.reloadData()
        
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        super.tableView(tableView, didSelectRowAt: indexPath)
        
        switch indexPath.row{
        case 0:
            statement()
        case 1:
            append()
        case 2:
            indexes()
        case 3:
            remove()
        case 4:
            ergodic()
        default:
            print("no more methods")
        }
    }
    
    fileprivate func statement() {
        let arrayA : Array<String> = ["1","2"]
        print(arrayA)
        print(arrayA.count)
        
        let arrayB : Array = [1,0.4,"hello"] as [Any]
        print(arrayB)
        
        let arrayC = Array(repeating: 0, count: 0)
        if arrayC.isEmpty {
            print("This Array is empty")
        }
    }
    
    fileprivate func append() {
        var arrayA : Array<String> = ["hello"]
        arrayA.append(" ")
        arrayA.append("world")
        print(arrayA)
        
        arrayA += ["dog","cat"]
        print(arrayA)
        
        arrayA.insert("not", at: 1)
        print(arrayA)
    }
    
    fileprivate func indexes() {
        var arrayA : Array<String> = ["hello","world","dog"]
        print(arrayA[2])
        
        arrayA[1...2] = ["cat","not"]
        print(arrayA)
    }
    
    fileprivate func remove() {
        var arrayA : Array<Int> = [1,2,3,4]
        arrayA.remove(at: 1)
        print(arrayA)
        
        arrayA.removeLast()
        print(arrayA)
        
        arrayA.removeAll()
        print(arrayA)
    }
    
    fileprivate func ergodic() {
        let arrayA : Array<Int> = [1,2,3,4]
        for subject in arrayA {
            print(subject)
        }
    }
}
